--[[Morgana Angel of Death(0.1) By Nightingale737
Features:
•     Hit-box Prodictions in Q skill
•     Auto W stuned targets With V prediction (causeing some erros)
•     Draw options for Q,W and Minion Collision 
•     Optional use of FastCollision or Normal Collision (use Normal Collision for now)
•     Optional customizable skill ranges
•     Optional Draw Q,W skill ranges
•     Auto Chain CC Q stun for Prodiction Donors


 
Changelog:
•  (0.2) Initial release, Works for me  
•  (0.21) Added Darw Minion Collision and Vprediction to Auto Stun on W (causeing some errors) ]]--
 
 
 
 
 
require "Prodiction"
require "VPrediction"
 
if myHero.charName ~= "Morgana" then return end
 
local qRange = 1300
local wRange = 925
 
       
local QReady, WReady, EReady, RReady = false, false, false, false
       
local Prodict = ProdictManager.GetInstance()
local ProdQ = Prodict:AddProdictionObject(_Q, qRange, 1200, 0.250, 72)
local ProdW = Prodict:AddProdictionObject(_W, wRange, 1200, 0.250, 175)
 
local ProdictQCol = nil
local ProdictQFastCol = nil

local VP = nil
local VP = VPrediction() 
 
local HKQ = string.byte("T")
 
 
 
function PluginOnLoad()
 
        AutoCarry.SkillsCrosshair.range = 1350
        test123()
        Menu()
        RebornCheck()
       
       
end
 
function PluginOnTick()
        Checks()
        if ValidTarget(Target) and (AutoCarry.MainMenu.AutoCarry) then
                     MorganaQStun()
                     MorganaVPW()
        end
               
         if ValidTarget(Target) and (AutoCarry.MainMenu.MixedMode) then
                        MorganaQMixMode()
         end
 
 
end
       
   
 
 
function PluginOnDraw()
        if not myHero.dead then
                if QReady and AutoCarry.PluginMenu.drawQ then
                        DrawCircle(myHero.x, myHero.y, myHero.z, qRange, 0x6600CC)
                end
                if WReady and AutoCarry.PluginMenu.drawW then
                        DrawCircle(myHero.x, myHero.y, myHero.z, wRange, 0x990000)
                end
                if ValidTarget(Target) and AutoCarry.PluginMenu.drawC  
                    then ProdictQCol:DrawCollision(myHero, Target) 
                end
        end
end
 
function Menu()
        AutoCarry.PluginMenu:addSubMenu("-- [Prodiction & Collision Settings] --", "extra")
       
     
        AutoCarry.PluginMenu.extra:addParam("ColSwap", "Use - Fast Collision (Reload)", SCRIPT_PARAM_ONOFF, false)
        
        AutoCarry.PluginMenu:addParam("KDonator", " Chain CC - Prodiction Donators only", SCRIPT_PARAM_ONOFF, false)
       
       
       
        AutoCarry.PluginMenu:addParam("sep1", "-- Autocarry Options --", SCRIPT_PARAM_INFO, "")
       
        AutoCarry.PluginMenu:addParam("useQ", "Use -  use Q ", SCRIPT_PARAM_ONOFF, true)
        AutoCarry.PluginMenu:addParam("useW", "Use -  Auto W stuned Targets", SCRIPT_PARAM_ONOFF, true)
        
        AutoCarry.PluginMenu:addParam("sep2", "-- Mixed Mode Options --", SCRIPT_PARAM_INFO, "")
        AutoCarry.PluginMenu:addParam("useQMixMode", "Use - QHarrass", SCRIPT_PARAM_ONOFF, true)
       
 
        AutoCarry.PluginMenu:addParam("sep3", "-- Drawing Options --", SCRIPT_PARAM_INFO, "")
        AutoCarry.PluginMenu:addParam("drawQ", "Draw - QRange", SCRIPT_PARAM_ONOFF, true)
        AutoCarry.PluginMenu:addParam("drawW", "Draw - WRange", SCRIPT_PARAM_ONOFF, true)
        AutoCarry.PluginMenu:addParam("drawC", "Draw - Minion Collision", SCRIPT_PARAM_ONOFF, true)
       
end
 
function Checks()
        QReady = (myHero:CanUseSpell(_Q) == READY)
        WReady = (myHero:CanUseSpell(_W) == READY)
        EReady = (myHero:CanUseSpell(_E) == READY)
        RReady = (myHero:CanUseSpell(_R) == READY)
        Target = AutoCarry.GetAttackTarget()
        Minion = AutoCarry.GetMinionTarget()
       
end
 
 
 
 
 
function MorganaQStun()
        if QReady and AutoCarry.PluginMenu.useQ  then
                ProdQ:GetPredictionCallBack(Target, CastQ)
        end
end

function MorganaQMixMode()
        if QReady and AutoCarry.PluginMenu.useQMixMode  then
                ProdQ:GetPredictionCallBack(Target, CastQ)
        end
end
 
 
 
function GetHitBoxRadius(Target)
        return GetDistance(Target, Target.minBBox)
end
 
function CastQ(unit, pos, spell)
        if GetDistance(pos) - getHitBoxRadius(unit)/2 < qRange then
                if AutoCarry.PluginMenu.extra.ColSwap then
                local willCollide = ProdictQFastCol:GetMinionCollision(pos, myHero)
                if not willCollide then CastSpell(_Q, pos.x, pos.z) end
                else
                local willCollide = ProdictQCol:GetMinionCollision(pos, myHero)
                if not willCollide then CastSpell(_Q, pos.x, pos.z) end
                end
        end
end
 


function MorganaVPW()
    if not AutoCarry.PluginMenu.KDonator  then
        for i, target in pairs(GetEnemyHeroes()) do
         CastPosition,  HitChance,  Position = VP:GetLineCastPosition(Target, 0.25,174 , wRange, 1600, myHero)
          if WReady and (AutoCarry.MainMenu.AutoCarry) and AutoCarry.PluginMenu.useW and  HitChance >= 4 and GetDistance(CastPosition) < 900 then CastSpell(_W,CastPosition.x, CastPosition.z) 
          end
      end 
  end

     
    
end  
 
 
 
 
 
function RebornCheck()
        if AutoCarry.Skills then IsSACReborn = true else IsSACReborn = false end
        if AutoCarry.PluginMenu.extra.ColSwap then
                require "FastCollision"
                ProdictQFastCol = FastCol(ProdictQ)
                PrintChat("<font color='#5C246E'>>> Morgana the Angel of Death!!. : Fast Collision Loaded!</font>")
        else
                require "Collision"
                ProdictQCol = Collision(qRange, 1900, 0.250, 80)
                PrintChat("<font color='#5C246E'>>> Morgana the Angel of Death!!. Normal Collision Loaded! </font>") end
end
 
 
function AfterImmobileFunc(unit, pos, spell)
 
        if  QReady and GetDistance(pos) < QRange  and AutoCarry.PluginMenu.KDonator then
        CastSpell(_Q, pos.x, pos.z)
        end
end
 
function OnImmobileFunc(unit, pos, spell)
 
        if  WReady and (AutoCarry.MainMenu.AutoCarry) and AutoCarry.PluginMenu.useW and AutoCarry.PluginMenu.KDonator then
        CastSpell(_W, pos.x, pos.z)
        end
end
 
 
function test123()
 
 for i = 1, heroManager.iCount do
           local hero = heroManager:GetHero(i)
           if hero.team ~= myHero.team then
             
              ProdW:GetPredictionOnImmobile(hero, OnImmobileFunc)
	      ProdQ:GetPredictionAfterImmobile(hero, AfterImmobileFunc)
           
           end
       end
       
end